home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / progrmng / cmlmcmpw.sit / Caml Light / Lib / cstring.mli < prev    next >
Encoding:
Text File  |  1991-05-01  |  5.7 KB  |  112 lines  |  [TEXT/MPS ]

  1. (* String operations, with sanity checks. *)
  2.  
  3. value string_length : string -> int = 1 "string_length"
  4.         (* Returns the length (number of characters) of the given string. *)
  5. ;;
  6. value nth_char : string -> int -> char
  7.         (* "nth_char s n" returns character number n in string s.
  8.            The first character is character number 0.
  9.            The last character is character number string_length s - 1.
  10.            Raises Invalid_argument "nth_char" if n is ouside the range
  11.            0 .. (string_length s - 1). *)
  12.   and set_nth_char : string -> int -> char -> char
  13.         (* "set_nth_char s n c" physically modifies string s,
  14.            replacing character number n by character c.
  15.            Raises Invalid_argument "set_nth_char" if n is ouside the range
  16.            0 .. (string_length s - 1). *)
  17. ;;
  18. value prefix ^ : string -> string -> string
  19.         (* "s1 ^ s2" returns a fresh string containing the concatenation of
  20.            strings s1 and s2. *)
  21.   and sub_string : string -> int -> int -> string
  22.         (* "sub_string s start len" returns a fresh string of length len,
  23.            containing characters number start through start + len - 1
  24.            of string s.
  25.            Raises Invalid_argument "sub_string" if start, len do not designate a
  26.            valid substring of s; that is, if start < 0, or len > 0, or
  27.            start + len > string_length s. *)
  28. ;;
  29. value create_string : int -> string = 1 "make_string"
  30.         (* "create_string n" returns a fresh string of length n,
  31.            containing random characters. *)
  32.   and make_string : int -> char -> string
  33.         (* "make_string n c" returns a fresh string of length n,
  34.            initialized to the character c. *)
  35. ;;
  36. value fill_string : string -> int -> int -> char -> string
  37.         (* "fill_string s start len c" physically modifies string s,
  38.            replacing characters number start through start + len - 1
  39.            by character c. String s is returned.
  40.            Raises Invalid_argument "fill_string" if start, len do not designate
  41.            a valid substring of s. *)
  42.   and blit_string : string -> int -> string -> int -> int -> unit
  43.         (* "blit_string s1 o1 s2 o2 len" copies len characters
  44.            from string s1, starting at character number o1, to string s2,
  45.            starting at character number o2. Works correctly even if s1 = s2
  46.            and the source chunk and destination chunk overlap.
  47.            Raises Invalid_argument "blit_string" if o1, len do not designate a
  48.            valid substring of s1, or if o2, len do not designate a valid
  49.            substring of s2. *)
  50.   and replace_string : string -> string -> int -> unit
  51.         (* "replace_string dest src start" copies all characters from string
  52.            src into string dst, starting at offset start.
  53.            Raises Invalid_argument "replace_string" if copying would overflow
  54.            string dest. *)
  55. ;;
  56. value string_for_read : string -> string
  57.         (* Returns a copy of its argument, with special characters represented
  58.            by escape sequences, following the lexical conventions of
  59.            CAML Light. *)
  60. ;;
  61. value string_length : string -> int = 1 "string_length"
  62.         (* Returns the length (number of characters) of the given string. *)
  63. ;;
  64. value nth_char : string -> int -> char
  65.         (* "nth_char s n" returns character number n in string s.
  66.            The first character is character number 0.
  67.            The last character is character number string_length s - 1.
  68.            Raises Invalid_argument "nth_char" if n is ouside the range
  69.            0 .. (string_length s - 1). *)
  70.   and set_nth_char : string -> int -> char -> char
  71.         (* "set_nth_char s n c" physically modifies string s,
  72.            replacing character number n by character c.
  73.            Raises Invalid_argument "set_nth_char" if n is ouside the range
  74.            0 .. (string_length s - 1). *)
  75. ;;
  76. value prefix ^ : string -> string -> string
  77.         (* "s1 ^ s2" returns a fresh string containing the concatenation of
  78.            strings s1 and s2. *)
  79.   and sub_string : string -> int -> int -> string
  80.         (* "sub_string s start len" returns a fresh string of length len,
  81.            containing characters number start through start + len - 1
  82.            of string s.
  83.            Raises Invalid_argument "sub_string" if start, len do not designate
  84.            a valid substring of s; that is, if start < 0, or len > 0, or
  85.            start + len > string_length s. *)
  86. ;;
  87. value fill_string : string -> int -> int -> char -> string
  88.         (* "fill_string s start len c" physically modifies string s,
  89.            replacing characters number start through start + len - 1
  90.            by character c. String s is returned.
  91.            Raises Invalid_argument "fill_string" if start, len do not designate
  92.            a valid substring of s. *)
  93.   and blit_string : string -> int -> string -> int -> int -> unit
  94.         (* "blit_string s1 o1 s2 o2 len" copies len characters
  95.            from string s1, starting at character number o1, to string s2,
  96.            starting at character number o2. Works correctly even if s1 = s2
  97.            and the source chunk and destination chunk overlap.
  98.            Raises Invalid_argument "blit_string" if o1, len do not designate a
  99.            valid substring of s1, or if o2, len do not designate a valid
  100.            substring of s2. *)
  101.   and replace_string : string -> string -> int -> unit
  102.         (* "replace_string dest src start" copies all characters from string
  103.            src into string dst, starting at offset start.
  104.            Raises Invalid_argument "replace_string" if copying would overflow
  105.            string dest. *)
  106. ;;
  107. value string_for_read : string -> string
  108.         (* Returns a copy of its argument, with special characters represented
  109.            by escape sequences, following the lexical conventions of
  110.            CAML Light. *)
  111.  
  112.